/******************************
Class Name: OOR_scheduled_AFAssigned 
Purpose: Scheduler for Aggregate Recurring Charges by MC at end of every month.
Author:  Accenture IDC
Requirement/Project Name: OOR
******************************/
global class OOR_scheduled_AFAssigned implements Schedulable{
    
        global void execute(SchedulableContext sc) {
            
            Account acct = new Account();
            //Need to query the unique single account by name as it is not having any other identifiers.
            acct = [Select Id ,OOR_Secondary_Account_Owner__c from Account where Name =: 'OOR AF Assigned Account' Limit 1];
                        
            OOR_AFAssigned classAFAssignedShedule = new OOR_AFAssigned(); // Calling the batch class to create order
            classAFAssignedShedule.AccountId = acct.Id; //Passing the OOR AF Assigned Account Id 
            if(acct.OOR_Secondary_Account_Owner__c!=null){
            classAFAssignedShedule.SecondaryOwner=acct.OOR_Secondary_Account_Owner__c;//Passign OOR Secondary Owner Id
            }
            classAFAssignedShedule.query = 'Select FirstName,LastName,SFA_Office__c,Id,ManagerId,Manager.FirstName,Manager.LastName,UserRole.Name from User where SFA_Office__c != NULL AND UserRole.Name Like \'OOR%\'';
            Database.executeBatch(classAFAssignedShedule,3);
        
        }
        //Test Method
        static testMethod void testAFAssigned() {
            test.starttest();
            OOR_scheduled_AFAssigned job = new OOR_scheduled_AFAssigned();
            String sch = '0 0 1 1 * ?';
            system.schedule('Scheduled AF_Assigned', sch, job);
            test.stopTest();
        }   
}